package com.example.com.test.impl;


import com.example.com.test.application.App;
import com.example.com.test.util.ACache;

import java.io.Serializable;
import java.util.HashMap;

/**
 * 作者： ch
 * 时间： 2018/6/13 0013-上午 9:43
 * 描述： 历史记录 实现
 * 来源：
 */


public class AudioImpl {

    private static final String AUDIO_CACHE = "AUDIO_CACHE";


    /**
     * 获取缓存的对象
     *
     * @return
     */
    public static AudioImplModel getModel() {
        ACache cache = ACache.get(App.getContext());
        AudioImplModel implModel = (AudioImplModel) cache.getAsObject(AUDIO_CACHE);
        return implModel;
    }

    /**
     * 保存
     *
     * @param model
     */
    public static void saveModel(AudioImplModel model) {
        ACache cache = ACache.get(App.getContext());
        cache.put(AUDIO_CACHE, model);
    }

    /**
     * 添加音频
     *
     * @param audioId
     */
    public static void addAudio(String audioId) {

        /*String userId = UserImpl.getUserId();
        if (TextUtils.isEmpty(userId)) {
            return;
        }
        AudioImplModel audioImplModel = getModel();
        if (audioImplModel == null) {
            audioImplModel = new AudioImplModel();
        }
        if (audioImplModel.getMap() == null) {
            audioImplModel.setMap(new HashMap<String, HashMap<String, String>>());
        }
        if (audioImplModel.getMap().containsKey(userId)) {
            HashMap<String, String> map = audioImplModel.getMap().get(userId);
            if (!map.containsKey(audioId)) {
                map.put(audioId, audioId);
            }
        } else {
            HashMap<String, String> map = new HashMap<>();
            map.put(audioId, audioId);
            audioImplModel.getMap().put(userId, map);
        }

        saveModel(audioImplModel);*/

    }

    /**
     * @param audioId
     * @return
     */
    public static boolean isRead(String audioId) {
/*
        String userId = UserImpl.getUserId();
        if (TextUtils.isEmpty(userId)) {
            return false;
        }
        AudioImplModel audioImplModel = getModel();
        if (audioImplModel == null) {
            return false;
        }
        if (audioImplModel.getMap() == null) {
            return false;
        }
        if (audioImplModel.getMap().containsKey(userId)) {
            HashMap<String, String> map = audioImplModel.getMap().get(userId);
            if (map.containsKey(audioId)) {
                return true;
            }
        } else {
            return false;
        }
*/


        return false;
    }


    public static class AudioImplModel implements Serializable {
        private HashMap<String, HashMap<String, String>> map;

        public HashMap<String, HashMap<String, String>> getMap() {
            return map;
        }

        public void setMap(HashMap<String, HashMap<String, String>> map) {
            this.map = map;
        }
    }

}
